package cn.demoxy.controller;

import cn.demoxy.annotation.Log;
import cn.demoxy.enums.BusinessTypeEnum;
import cn.demoxy.model.dto.DemoTenantDTO;
import cn.demoxy.model.entity.DemoTenant;
import cn.demoxy.result.R;
import cn.demoxy.service.IDemoTenantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

/**
 * @auther demo
 * @date 2022/5/17 11:22
 * 租户表控制层
 */
@Api(tags = "租户接口信息")
@RestController
@RequestMapping("/admin/demo-tenant")
@AllArgsConstructor
@CrossOrigin
public class DemoTenantController {

    /**
     * 租户service
     */
    IDemoTenantService tenantService;

    /**
     * 根据条件分页查询租户列表
     *
     * @param TenantDTO
     * @return
     */
    @ApiOperation(value = "根据条件分页查询租户列表")
    @PostMapping("/page")
    public R page(@RequestBody DemoTenantDTO TenantDTO) {
        return R.ok(tenantService.findAllTenantByKeyword(TenantDTO));
    }

    /**
     * 添加租户信息
     *
     * @param tenant
     * @return
     */
    @ApiOperation(value = "添加租户信息")
    @PostMapping("/save")
    @Log(title = "租户管理租户新增",businessType = BusinessTypeEnum.INSERT)
    @RequiresPermissions("demo-tenant:save")
    public R save(@RequestBody DemoTenant tenant) {
        return R.ok(tenantService.save(tenant));
    }

    /**
     * 编辑租户信息
     *
     * @param tenant
     * @return
     */
    @ApiOperation(value = "编辑租户信息")
    @PostMapping("/update")
    @Log(title = "租户管理租户信息修改",businessType = BusinessTypeEnum.UPDATE)
    @RequiresPermissions("demo-tenant:update")
    public R update(@RequestBody DemoTenant tenant) {
        return R.ok(tenantService.updateById(tenant));
    }

    /**
     * 删除租户信息
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除租户信息")
    @PostMapping("/delete/{id}")
    @Log(title = "租户管理租户删除",businessType = BusinessTypeEnum.DELETE)
    @RequiresPermissions("demo-tenant:delete")
    public R delete(@PathVariable("id") String id) {
        return R.ok(tenantService.removeById(id));
    }
}
